home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / vocpak20.zip / DECOMPR.C < prev    next >
C/C++ Source or Header  |  1993-09-01  |  2KB  |  89 lines

  1. /*
  2.  * Vocpack 2.0 Library  -  (C) 1993 Nicola Ferioli
  3.  *
  4.  * This program shows how to decompress a file using Vocpack library functions.
  5.  * Link this program with one of the libraries VP_?.LIB, depending on the
  6.  * memory model used.
  7.  * To improve performance you can add disk buffering ( setvbuf() ).
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include "vocpack.h"
  12.  
  13.  
  14. FILE *In,    /* source file to be decompressed */
  15.      *Out;    /* destination file */
  16.  
  17.  
  18. /*
  19.  * I/O functions needed by Vocpack Library
  20.  */
  21.  
  22. int VP_Input (void)            /* input char from source file */
  23. {
  24.  return getc(In);
  25. }
  26.  
  27. void VP_InputRewind (void)        /* rewind source file */
  28. {
  29.  rewind(In);
  30. }
  31.  
  32. /* VP_Output and VP_OutputSeek are not needed when unpacking */
  33. void VP_Output () { return; }
  34. void VP_OutputSeek () { return; }
  35.  
  36.  
  37.  
  38. /*
  39.  * MAIN
  40.  */
  41.  
  42. void main (int argc, char *argv[])
  43. {
  44.  int c;            /* character to write to output file */
  45.  
  46.  
  47.  /* check command-line parameters */
  48.  if (argc != 3) {
  49.     puts("\nUsage:  DECOMPR <source> <dest>");
  50.     return; }
  51.  
  52.  /* open source and destination files */
  53.  if ( (In = fopen(argv[1], "rb")) == NULL ) {
  54.     printf("\nFile not found %s\n", argv[1]);
  55.     return; }
  56.  
  57.  if ( (Out = fopen(argv[2], "wb")) == NULL ) {
  58.     printf("\nCan't create %s\n", argv[2]);
  59.     return; }
  60.  
  61.  /* detect source file content */
  62.  switch (VP_InitUnpack(NULL)) {        /* NULL = discard info */
  63.     case VP_OK:
  64.         break;            /* ok, file can be unpacked */
  65.  
  66.     case VP_ERR_NOTVP:
  67.         printf("\n%s is not compressed with Vocpack\n", argv[1]);
  68.         return;
  69.  
  70.     case VP_ERR_OLDMETHOD:
  71.         printf("\n%s is compressed with Vocpack 1.0\n", argv[1]);
  72.         return;
  73.  
  74.     case VP_ERR_UNKMETHOD:
  75.         printf("\n%s is compressed with an unknown method\n", argv[1]);
  76.         return;
  77.  }
  78.  
  79.  /* decompression loop: decompress a character and write it */
  80.  while ( (c = VP_Unpack()) != VP_EOF )
  81.     putc(c, Out);
  82.  
  83.  /* end of decompression */
  84.  VP_EndUnpack();
  85.  
  86.  /* close files */
  87.  fclose(In);
  88.  fclose(Out);
  89. }